//
//  GZStatus.swift
//  sinaweibo
//
//  Created by mac book pro on 16/3/26.
//  Copyright © 2016年 finish. All rights reserved.
//

import UIKit
/// 微博模型
class GZStatus: NSObject {
    /// 微博创建时间
    var created_at: String?
    /// 微博ID
    var id: Int64 = 0
    /// 微博内容
    var text: String?
    /// 微博来源
    var source: String?
    /// 微博配图
    var pic_urls: [[String:AnyObject]]?{
        didSet{
            let count = pic_urls?.count ?? 0
            if count == 0{
                return
            }
            storePictureURLs = [NSURL]()
            //遍历数组
            for dict in pic_urls!{
                let urlString = dict["thumbnail_pic"] as! String
                let url = NSURL(string: urlString)!
                storePictureURLs?.append(url)
            }
        }
    }
    /// 微博配图
    var storePictureURLs: [NSURL]?
    /// 回复数
    var reposts_count: Int = 0
    /// 评论数
    var comments_count: Int = 0
    /// 表太数
    var attitudes_count: Int = 0
    /// 用户数据
    var user: GZUser?
    /// 被转发的微博
    var  retweeted_status: GZStatus?
    //字典转模型
    init(dict: [String:AnyObject]){
        super.init()
        //KVC赋值
        setValuesForKeysWithDictionary(dict)
    }
    override func setValue(value: AnyObject?, forKey key: String) {
        if  key == "user"{
            if let dict = value as? [String:AnyObject]{
                user = GZUser(dict: dict)
            }
            return
        }
        if key == "retweeted_status"{
            if let dict = value as? [String:AnyObject]{
                retweeted_status = GZStatus(dict: dict)
            }
            return
        }
        super.setValue(value, forKey: key)
    }
    //处理setvalue forkey 找不到key时调用
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    //对象打印方法
    override  var description: String {
        get{
            let keys = ["created_at","id","text","source","pic_urls","reposts_count","comments_count","attitudes_count","user","retweeted_status"]
            return self.dictionaryWithValuesForKeys(keys).description
            
        }
    }
    
}
